#-------------------------------------------------------------------------------
# Name:       audio_converter_windows.py
# Purpose:    Convert text to audio files
#
# Authors:    Glenn Ramsey <glenn.ramsey@slidespeech.com>
#
# Copyright:  (c) Slidespeech Ltd 2012
# Licence:    MIT license
#-------------------------------------------------------------------------------

import os
import subprocess

class AudioConfig:
    ttsURL = "http://www.microsoft.com"
    ttsEngine = "Windows Native"
    ttsExe = "sapi2wav"
    oggEncoder = "oggenc2"
    mp3Encoder = "lame"

def encodeOgg(path, inFileName, outFileName):
    return subprocess.call([AudioConfig.oggEncoder, inFileName, '-o', outFileName])

def encodeMp3(path, inFileName, outFileName):
    return subprocess.call([AudioConfig.mp3Encoder, '-V2', inFileName, outFileName])

def textToAudio(text, language, path, basename):
    filename = os.path.join(path, basename + '.wav')
    print "Text:", text
    ret = subprocess.call([AudioConfig.ttsExe, filename, '1', '-t', text])
    if ret:
        raise RuntimeError("Could not generate audio, {0} failed".format(AudioConfig.ttsExe))

    return filename
